<template>
  <el-card class="filter-card" shadow="never">
    <el-form :model="localQueryParams" inline>
      <el-form-item label="入库单号">
        <el-input
          v-model="localQueryParams.inboundNumber"
          placeholder="输入入库单号"
          clearable
          style="width: 200px"
          class="input-field"
        />
      </el-form-item>
      
      <el-form-item label="供应商">
        <el-select 
          v-model="localQueryParams.supplierId" 
          clearable 
          placeholder="全部供应商" 
          class="form-item-width select-field"
        >
          <el-option
            v-for="supplier in suppliers"
            :key="supplier.id"
            :label="supplier.name"
            :value="supplier.id"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="发票状态">
        <el-select 
          v-model="localQueryParams.invoiceStatus" 
          clearable 
          placeholder="全部状态" 
          class="form-item-width select-field"
        >
          <el-option label="待开票" value="pending" />
          <el-option label="已收票（未上传）" value="received" />
          <el-option label="已上传" value="uploaded" />
        </el-select>
      </el-form-item>
      
      <el-form-item label="入库日期">
        <el-date-picker
          v-model="localQueryParams.inboundDateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD"
          class="date-picker-field"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button 
          type="primary" 
          :icon="Search" 
          @click="handleSearch"
          class="search-btn"
        >
          查询
        </el-button>
        <el-button 
          :icon="Refresh" 
          @click="handleReset"
          class="reset-btn"
        >
          重置
        </el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import { ref, reactive, watch, defineProps, defineEmits } from 'vue'
import { Search, Refresh } from '@element-plus/icons-vue'

interface Supplier {
  id: number
  name: string
}

interface QueryParams {
  inboundNumber: string
  supplierId: number | null
  invoiceStatus: string
  inboundDateRange: string[]
}

const props = defineProps<{
  queryParams: QueryParams
  suppliers: Supplier[]
}>()

const emit = defineEmits<{
  (e: 'update:queryParams', value: QueryParams): void
  (e: 'search'): void
  (e: 'reset'): void
}>()

// 创建本地副本以避免直接修改 props
const localQueryParams = reactive({ ...props.queryParams })

// 监听 props 变化并更新本地副本
watch(() => props.queryParams, (newVal) => {
  Object.assign(localQueryParams, newVal)
}, { deep: true })

// 监听本地副本变化并触发更新事件
watch(localQueryParams, (newVal) => {
  emit('update:queryParams', { ...newVal })
}, { deep: true })

const handleSearch = () => {
  emit('search')
}

const handleReset = () => {
  // 重置本地副本
  Object.assign(localQueryParams, {
    inboundNumber: '',
    supplierId: null,
    invoiceStatus: '',
    inboundDateRange: []
  })
  emit('reset')
}
</script>

<style scoped>
.filter-card {
  margin-bottom: 16px;
  transition: all 0.3s ease;
}

.filter-card:hover {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

/* 表单元素悬停效果 */
.input-field:hover,
.select-field:hover,
.date-picker-field:hover {
  transform: translateY(-1px);
  transition: all 0.3s ease;
}

/* 按钮动画效果 */
.search-btn,
.reset-btn {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.search-btn:hover,
.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.search-btn:active,
.reset-btn:active {
  transform: translateY(0);
}

.search-btn::after,
.reset-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.search-btn:active::after,
.reset-btn:active::after {
  width: 300px;
  height: 300px;
}

/* 查询按钮特殊样式 */
.search-btn {
  background-color: #409eff;
  border-color: #409eff;
  color: white;
}

.search-btn:hover {
  background-color: #66b1ff;
  border-color: #66b1ff;
}

/* 重置按钮特殊样式 */
.reset-btn {
  background-color: #909399;
  border-color: #909399;
  color: white;
}

.reset-btn:hover {
  background-color: #a6a9ad;
  border-color: #a6a9ad;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .filter-card :deep(.el-form-item) {
    margin-bottom: 12px;
  }
  
  .filter-card :deep(.el-form-item__content) {
    display: flex;
    flex-wrap: wrap;
  }
  
  .filter-card :deep(.el-input),
  .filter-card :deep(.el-select) {
    width: 100% !important;
  }
  
  .filter-card :deep(.el-button) {
    margin-bottom: 8px;
  }
}
</style>